package com.woman.beautylive.presentation.ui.main.find;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.woman.beautylive.R;
import com.woman.beautylive.domain.LocalDataManager;
import com.woman.beautylive.presentation.ui.base.BaseFragment;
import com.woman.beautylive.presentation.ui.main.find.paihangbangbean.MeiLiBangBean;

import java.util.List;

/**
 * Created by admin on 2016/9/20.
 */
public class FuHaoBangFragment extends BaseFragment implements MeiLiBangInterFace {
   ListView billbord_recyclerview;
    private PaiHangBangPresenter pengyouqunpresenter;
    private MeiLiBangAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_charm_billboard;
    }

    @Override
    protected void initViews(View view) {

        View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.header_meilipaihangbang, null);
        billbord_recyclerview = $(view,R.id.billbord_recyclerview);

        billbord_recyclerview.addHeaderView(headerView);
        pengyouqunpresenter = new PaiHangBangPresenter(this);
        System.out.println(LocalDataManager.getInstance().getLoginInfo().getToken() + "token" + LocalDataManager.getInstance().getLoginInfo().getCity());
        pengyouqunpresenter.getFuHaoBang(1);
    }

    public static FuHaoBangFragment newInstance() {
        return new FuHaoBangFragment();
    }

    @Override
    public void showResult(List<MeiLiBangBean> list) {
        if(list!=null){
            if(adapter==null) {
                adapter = new MeiLiBangAdapter(list);
                billbord_recyclerview.setAdapter(new MeiLiBangAdapter(list));
            }else{
                adapter.notifyDataSetChanged();
            }
        }
    }

    @Override
    public void showData(List list) {

    }

    @Override
    public void appendData(List list) {

    }
    public class MeiLiBangAdapter extends BaseAdapter {
        List<MeiLiBangBean> list;
        public MeiLiBangAdapter(List<MeiLiBangBean> list){
            this.list=list;
        }
        @Override
        public int getCount() {
            return list==null?0:list.size();
        }

        @Override
        public Object getItem(int position) {
            return list==null?0:list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_billboard, null);
                holder = new Holder();
                holder.item_billboard_tag1 = (ImageView) convertView.findViewById(R.id.item_billboard_tag1);
                holder.item_billboard_tag2 = (ImageView) convertView.findViewById(R.id.item_billboard_tag2);
                holder.txt_number = (TextView) convertView.findViewById(R.id.txt_number);
                holder.item_billboard_name = (TextView) convertView.findViewById(R.id.item_billboard_name);
                holder.item_billboard_contant = (TextView) convertView.findViewById(R.id.item_billboard_contant);
                convertView.setTag(holder);
            } else {
                holder= (Holder) convertView.getTag();
            }
            holder.item_billboard_name.setText(this.list.get(position).getNickname());
            return convertView;
        }

        class Holder {
            TextView txt_number, item_billboard_name, item_billboard_contant;
            ImageView item_billboard_tag1, item_billboard_tag2;
        }
    }
}
